package com.thb.mail.util;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.thb.configure.config.Config;
import com.thb.mail.model.MailSenderInfo;

public class MailUtils {
	
	private static final Logger logger = LoggerFactory.getLogger(MailUtils.class);
	
	public static boolean SendPasswdMail(Config config,String email,String content,int validMinutes){
		  logger.info(String.format("SendPasswdMail  email :[ %s ],content [ %s ]",email,content));
		  MailSenderInfo mailInfo = new MailSenderInfo();
		  mailInfo.setMailServerHost(config.getMailServer());
		  mailInfo.setMailServerPort(config.getMailPort());
		  mailInfo.setValidate(true);
		  
		  mailInfo.setUserName(config.getUserName());
		  mailInfo.setPassword(config.getUserPasswd());
		  mailInfo.setFromAddress(config.getFromMail());
		  mailInfo.setToAddress(email);
		  mailInfo.setSubject("忘记密码-获取验证码");
		  StringBuffer buffer = new StringBuffer();
		  buffer.append(String.format("您修改密码的验证码是 [ %s ],验证码的有效期是 [ %s ] 分钟 \n", content,validMinutes));
		  buffer.append("请尽快完成修改密码");
		  mailInfo.setContent(buffer.toString());
		  return sendMail(mailInfo);
	}
	
	private static boolean sendMail(MailSenderInfo mailInfo){
		  logger.info("sendMail  mailInfo");
//		  SimpleMailSender sms = new SimpleMailSender();
//		  sms.sendTextMail(mailInfo);
		  return SimpleMailSender.sendHtmlMail(mailInfo);
		
	}
	 
}
